from app import db
from datetime import datetime

class VepResult(db.Model):
    """VEP核算结果模型"""
    __tablename__ = 'vep_results'
    
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False, comment='核算年份')
    vepName = db.Column(db.String(100), nullable=False, comment='VEP项目名称')
    vepCity = db.Column(db.String(50), nullable=False, comment='市级地区名称')
    vepDistrict = db.Column(db.String(50), nullable=False, comment='区级地区名称')
    vepTown = db.Column(db.String(50), nullable=False, comment='镇级地区名称')
    vepResult = db.Column(db.Float, comment='VEP核算总结果（万元）')
    provisioningServices = db.Column(db.Float, comment='物质供给结果（万元）')
    regulatingServices = db.Column(db.Float, comment='调节服务结果（万元）')
    culturalServices = db.Column(db.Float, comment='文化服务结果（万元）')
    creator = db.Column(db.String(50), comment='数据创建者用户名')
    updater = db.Column(db.String(50), comment='数据更新者用户名')
    created_at = db.Column(db.DateTime, default=datetime.utcnow, comment='数据创建时间')
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment='数据更新时间')
    
    def __repr__(self):
        return f'<VepResult {self.year}-{self.vepName}-{self.vepCity}-{self.vepDistrict}-{self.vepTown}>'
    
    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'vepName': self.vepName,
            'vepCity': self.vepCity,
            'vepDistrict': self.vepDistrict,
            'vepTown': self.vepTown,
            'vepResult': self.vepResult,
            'provisioningServices': self.provisioningServices,
            'regulatingServices': self.regulatingServices,
            'culturalServices': self.culturalServices,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        } 